﻿#region Usings

using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;



#endregion

namespace PolyGameEngine.GamePieces
{
    public class AnimatedRectangleEffectGamePiece: RectangleEffectTile
    { 
        Texture2D Spritesheet;

        public int counterStop;
       public int divideBy;

        public AnimatedRectangleEffectGamePiece(PhysicsGame PhysicsGame, World World, Material Material, Vector2 Position, Vector2 EffectOffset,float Rotation,
            Texture2D SpriteSheet, int speed, float DrawingDepth, int saveLineIndex, string GPID)
            : base(PhysicsGame, World, Material, Position, Rotation, EffectOffset, 50, 50, 50, 50, DrawingDepth, saveLineIndex, GPID)
       {
           Spritesheet = SpriteSheet;
           body.IgnoreCCD = false;
           
           counterStop = (Spritesheet.Width/50) * speed;
           divideBy = speed;
       }

       int counter = 0;
       public override void Effect()
       {
           base.Effect();
       }

       public override void Update(GameTime gameTime)
       {
           if (++counter >= counterStop)
               counter = 0;
           base.Update(gameTime);
       }
       public override void Draw(GameTime gameTime)
       {
           Rectangle frame = new Rectangle(50 * (counter / divideBy) , 0, 50, 50);
           Vector2 origin = new Vector2(25, 25);
           spriteBatch.Draw(Spritesheet, position + _ScreenOffset, frame, Color.White,rotation, origin, 1, SpriteEffects.None, drawingDepth);
       }
    }
}
